import { Component } from "@/components/low-code/core";
import { LowCodeImp } from "@/components/low-code/core/type";
import { Cell } from "@/components/low-code/core/cell";
import { ElMessage } from "element-plus";


export const useComponentPretreatment = (lowCode: LowCodeImp, component: { type?: string, items: Array<any> }, index: number) => {

    /****
     * 如果是弹框组件 阻止拖入其他容器组件 只能在当前根节点拖入
     */
    if (component.type && component.items[index].type == "dialog") {
        component.items.splice(index, 1);
        ElMessage.warning("弹框组件只能拖入最外层容器");
        return true;
    }

    /****
     * 如果是弹框 需要暂时禁止其他组件拖入
     */
    if (!component.type && component.items[index].type == "dialog") {
        lowCode.disabled = true;
    }


    /****
     * 格栅组件需要对默认cell实例化
     */
    if (component.items[index].type == "row") {
        component.items[index].items = component.items[
            index
        ].items?.map((cell: any) => {
            return new Cell(cell, lowCode);
        });
    }

}